package com.cet.designapplication.deprecated.state;

import com.cet.designapplication.utils.RedisCommonProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author NSOC
 */
@Component
public class DeprecatedStartOrder extends DeprecatedAbstractOrderState {

    @Autowired
    private RedisCommonProcessor redisCommonProcessor;

    @Autowired
    private DeprecatedWaitPay deprecateWaitPay;

    @Override
    protected DeprecatedOrder createOrder(String orderId, String productId, DeprecateOrderContext context) {
        DeprecatedOrder order = DeprecatedOrder.builder()
                .orderId(orderId)
                .productId(productId)
                .state(ORDER_WAIT_PAY)
                .build();

        redisCommonProcessor.set(orderId, order, 900);
        context.setCurrentState(deprecateWaitPay);
        notifyObservers(orderId, ORDER_WAIT_PAY);
        return order;
    }
}
